package uy.edu.ort.suscriptores;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.log4j.Logger;

/**
 *
 * @author Leo
 */
@MessageDriven(mappedName = "jms/Internacionales", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
    @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
    @ActivationConfigProperty(propertyName = "clientId", propertyValue = "InternacionalesMDB"),
    @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "InternacionalesMDB")
})
public class InternacionalesMDB implements MessageListener {
    
    static Logger logger = Logger.getLogger(InternacionalesMDB.class);
    
    public InternacionalesMDB() {
    }
    
    @Override
    public void onMessage(Message message) {
        if (message != null) {
            // Valido que el mensaje obtenido sea del tipo esperado
            if (message instanceof TextMessage) {
                TextMessage m = (TextMessage) message;
                try {
                    logger.info(m.getText());
                } catch (JMSException ex) {
                    logger.error(ex.getMessage());
                }
            }
        } 
    }
}
